//-----------------------------------------------------------------------
// <copyright file="ScopeCollection.cs" company="Alan Rodrigues">
//     Copyright (c) Alan Rodrigues. All rights reserved.
// </copyright>
// <developed>Alan Rodrigues (operninha@gmail.com)</developed>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.Interop.Security.AzRoles;

namespace Authorization
{
    /// <summary>
    /// <see cref="Application"/> Scope
    /// </summary>
    public class ScopeCollection : Collection<Scope> // List<Scope>
    {
        ///// <summary>
        ///// Construtor
        ///// </summary>
        ///// <param name="capacity">capacity</param>
        //public ScopeCollection(int capacity)
        //    : base(capacity)
        //{
        //}

        /// <summary>
        /// Default Construtor
        /// </summary> 
        public ScopeCollection()
        {
        }

        public ScopeCollection(IList<Scope> list)
            : base(list)
        {
        }


        /// <summary>
        ///  Converts AzMan Scope
        /// </summary>
        /// <param name="application"><see cref="Application" /></param>
        /// <param name="azScopes"><see cref="IAzScopes"/></param>
        /// <returns>Retorna os <see cref="ScopeCollection"/> convetidos</returns>
        internal ScopeCollection(Application application, IAzScopes azScopes)
        {
            if (azScopes == null)
            {
                throw new ArgumentNullException("azScopes");
            }

            foreach (IAzScope2 azScope in azScopes)
            {
                Add(new Scope(application, azScope));
            }
        }

        /// <summary>
        ///  Returns scope names
        /// </summary>
        /// <returns>Array com os names dos scopeNames</returns>
        public string[] GetScopeNames()
        {
            return GetScopeNames(this);
        }

        /// <summary>
        ///  Returns scope names
        /// </summary>
        /// <param name="scopes">scopeNames</param>
        /// <returns>Array with Scope Names</returns>
        public static string[] GetScopeNames(IList<Scope> scopes)
        {
            string[] strScopes;

            if (scopes == null || scopes.Count == 0)
            {
                strScopes = new[] {""};
            }
            else
            {
                strScopes = new string[scopes.Count];
                for (int i = 0; i < scopes.Count; i++)
                {
                    strScopes[i] = scopes[i].Name;
                }
            }

            return strScopes;
        }
    }
}